import { useMemo, useState } from "react";
import styles from "./index.module.less";
import { getTableColumns, getSearchColumns } from "./constant";
import SuperTable from "@/components/SuperTable";
import cs from "classnames";
import { getAlertList } from "@/api/modules/alert";
import { RESULT_CODES } from "@/api/helper/ResultCode";
import useUrl from "@/hooks/useUrl";
import SearchBox from "@/components/SearchBox";
import { getAllOrgList, getDictByCode } from "@/api/modules/dict";
import { useRequest } from "ahooks";
import { cloneDeep, omit } from "lodash";

export default () => {
	const { navigate } = useUrl();
	const [params, setParams] = useState({});
	const { data: msgTypeList } = useRequest(() => getDictByCode({ parentId: 0, code: "FC_TYPE" }));

	const handleRequest = async (params: any, sortInfo: any) => {
		const paramsCopy = cloneDeep(params);
		const newParams = omit(paramsCopy, ['pageSize', 'current'])
		const requestData: any = {
			page: {
				pageSize: params.pageSize,
				pageNum: params.current
			},
			...newParams
		};

		const res = await getAlertList(requestData);
		return {
			total: res?.data?.total ?? 0,
			data: res?.data?.list ?? []
		};
	};

	const remark = {
			label: "备注",
			value: "remark"
		},
		deleteEnum = {
			label: "删除",
			value: "delete"
		};

	const newColumns = [
		...getTableColumns({ params, msgTypeList }),
		{
			title: "操作",
			width: 80,
			fixed: "right",
			dataIndex: "action-render",
			onClick: (key: string, record: any) => {
				switch (key) {
					case "remark":
						// navigate(`/dock/detail?active_id=${record.active_id}`, { state: record });
						break;
					case "deleteEnum":
						// navigate(`/dock/detail?active_id=${record.active_id}`, { state: record });
						break;
				}
			},
			options: (record: any) => {
				return [remark, deleteEnum];
			}
		}
	];

	const NEW_SEARCH_COLUMNS = useMemo(() => {
		return getSearchColumns({msgTypeList});
	}, [msgTypeList]);

	const handleSearch = (e: any) => {
		setParams(e);
	};


	return (
		<div className={styles.flexContainer}>
			<div className={styles.rightModule}>
				<SearchBox columns={NEW_SEARCH_COLUMNS} onSearch={handleSearch} >
					<div></div>
				</SearchBox>
				<div
					className={cs({
						[styles.container]: true
					})}
				>
					<SuperTable
						params={{
							...params,
						}}
						// bordered
						rowKey="id"
						columns={newColumns}
						request={handleRequest}
						scroll={{ x: "900" }}
					/>
				</div>
			</div>

		</div>
	);
};
